import { getSnssaiByMdn, getServTask, createBusinssByApp } from './mockFuns'
import { Toast } from 'vant'

const callApi = (url, param, type) => {
  return new Promise((resolve, reject) => {
    // loading
    Toast.loading({
      forbidClick: true
    })
    setTimeout(() => {
      console.log('url', url)
      // 获取url对应的mock方法
      const apiFun = getMockFun(url)
      // 调用mock接口
      Toast.clear()
      console.log('apiFun', apiFun(param))
      resolve(apiFun(param).data)
    }, 1500)
  })
}

const getMockFun = (url) => {
  const mockFunUrl = {
    'api/rest/worksheet/v1/5GSlice/getSnssaiByMdn': getSnssaiByMdn,
    'api/rest/worksheet/v1/5GSlice/createBusinssByApp': createBusinssByApp,
    'api/rest/worksheet/v1/5GSlice/getServTask': getServTask
  }

  return mockFunUrl[url]
}

export default callApi
